package adfc2.tasks;

import adfc2.actions.PickupAction;
import adfc2.core.Action;
import adfc2.core.Creature;
import adfc2.core.Task;
import adfc2.entities.DroppedItem;

/**
 * Created by IntelliJ IDEA.
 * User: aimozg
 * Date: 29.01.12
 * Time: 1:29
 */
public class PickupTask extends Task {

    public final DroppedItem target;
    private MoveTask moving;

    public PickupTask(Creature actor, DroppedItem target) {
        super(actor);
        this.target = target;
    }

    @Override
    public Action nextAction() {
        if (target.isRemoved()) {
            completed();
            return null;
        } else if (actor.getXY() == target.getXY()) {
            return new PickupAction(actor, target);
        } else {
            if (moving == null) moving = new MoveTask(actor, target.getXY(), false);
            return moving.nextAction();
        }
    }

    @Override
    public String shortName() {
        return "pickup " + target.shortName();
    }

    @Override
    public String toString() {
        return "PickupTask[" + target + "]";
    }
}
